<%= javascript_include_tag :fckeditor %>
 <%= form.hidden_field :user_id %>
 
 <%= form.hidden_field :point_x %>
 <%= form.hidden_field :point_y %>
 <%= form.hidden_field :zoom %>
 
 <table cellspacing="0" cellpadding="0" border="0" class="addPostPanel">
    <tbody>
		<tr>
      <td valign="top"> </td>
    </tr>
    <tr>
      <td valign="top" rowspan="2"><%= avatar(current_user) %></td>
      </td>
    </tr>
    <tr>
      <td valign="bottom" colspan="2">
					<strong>тема:</strong> <%= form.text_field :title %>
					<%#= form.select :article_type, Article::ARTICLE_TYPE %>
			</td>
    </tr>
  </tbody></table>
  <div class="redactor">
  	<%= fckeditor_textarea(:article, :content, :toolbarSet => 'Simple', :width => '100%', :height => '500px')%>
  </div>
  <table cellspacing="0" cellpadding="0" border="0" class="subPanel">
  <tbody><tr>
    <td><strong>метки записи:</strong></td>
    <td colspan="3"><%= form.text_field :tag_list, :style=>"width: 525px;" %></td>
    </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td colspan="2"><div class="submit"><input type="submit" value="опубликовать запись"/></div></td>
    </tr>
</tbody></table>

<div id="image_items">
 <% @images.each do |t| %>
      <%= render :partial => "includes/image_item", :object => t %>
      <%=t.filename%>
 <% end %>
</div>

<%= add_images_item_link("добавить картинку") %>

<br/><br/>

<%= link_to_function "Показать на карте", "init_gmap()" %><br/>


<div id="map_div_id" style="width:695px;height:500px" ></div>

<% content_for :head, (GMap.header) %>

<script type='text/javascript'>
	var map;
  var marker;
  
  <%= "Event.observe(window, 'load', init_gmap)" if !@article.new_record? && @article.is_gmap? %>
  
	function init_gmap()
	{
		var zoom = parseInt($('article_zoom').value);
		var lat = parseFloat($('article_point_x').value);
		var lng = parseFloat($('article_point_y').value);
		
		if (!zoom) zoom = 6;
		if (!lat) lat = 49.023461;
		if (!lng) lng = 31.201172;
		
		marker = new GMarker(new GLatLng(lat, lng), {draggable : true, title : "Метка"});


		if (GBrowserIsCompatible()) 
		{
			map = new GMap2(document.getElementById("map_div_id"));
			map.setCenter(new GLatLng(lat, lng), zoom);
			map.setMapType(G_HYBRID_MAP);

			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			
			GEvent.addListener(marker, "dragstart", function() {
          map.closeInfoWindow();
      });

      GEvent.addListener(marker, "dragend", function() {
      	//marker.openInfoWindowHtml("Just bouncing along...");
      	point = marker.getPoint();
      	$('article_point_x').value = point.lat();
      	$('article_point_y').value = point.lng();
      	$('article_zoom').value = map.getZoom();
      });

      map.addOverlay(marker);
		}
	}
</script>
